﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using SSS.AlphaNN.Logic;

namespace SSS.AlphaNN.Components
{
    public partial class Source : DataMedium
    {
        /// <summary>
        /// Конструктор
        /// </summary>
        public Source( UserControl parent )
        {
            InitializeComponent();

            Visible = false;

            this.Parent = parent;

            //SetSlotsAmount(countSignal);

            this.BackColor = Color.GhostWhite;

           
                                   
        }
              
        /// <summary>
        /// 
        /// </summary>
        /// <param name="slotsAmount"></param>
        public override void SetSlotsAmount(int slotsAmount)
        {
            int offset = 5;
            int innerSpace = 2;

            Slot slot = new Slot();

            for ( int i = 0; i < slotsAmount; i++ )
            {   
                slot = new Slot();
                
                slot.Name = "slot2_" + ( i + 1 ).ToString();
                //вот эта строчка  меня убила
                ( this.Parent as WorkGround ).Controls.Add( slot );
                base.Slots.Add( slot );

                base.Slots[i].Left = this.NoneScaleLocation.X + this.NoneScaleSize.Width - slot.NoneScaleSize.Width;
                base.Slots[i].Top = this.NoneScaleLocation.Y + offset;

                slot.Visible = false;
                slot.Owner = this;

                offset += slot.Height + innerSpace;
            }

            base.NoneScaleSize = new Size( base.NoneScaleSize.Width,  slot.Top - this.NoneScaleLocation.Y + slot.Height + 5  );
            
            this.Refresh();
        }

        /// <summary>
        /// 
        /// </summary>
        public override void Scale()
        {
            base.Scale();

            //if ( base.Slots.Count > 0 )
            //{
            //    base.NoneScaleSize = new Size( base.NoneScaleSize.Width, Slots.Count * base.Slots[Slots.Count - 1].NoneScaleSize.Height + Slots.Count * 2 + 10 );
            //}

            //int offset = 5 + ( int )( 5 * base.Zoom / 100 );
            //int innerSpace = 2 + ( int )( 2 * base.Zoom / 100 );

            //Slot slot;

            //for ( int i = 0; i < base.Slots.Count; i++ )
            //{
            //    slot = Slots[i];

            //    slot.Left = this.Width - slot.Width;
            //    slot.Top = offset;


            //    offset += slot.Height + innerSpace;
            //}

            if ( base.Slots.Count > 0 )
            {
                int offset = 5;
                int innerSpace = 2;

                Slot slot = new Slot();

                for ( int i = 0; i < base.Slots.Count; i++ )
                {
                    slot = base.Slots[i];

                    slot.Size = new Size( ( int )( slot.NoneScaleSize.Width + slot.NoneScaleSize.Width * Zoom / 100 ), ( int )( slot.NoneScaleSize.Height + slot.NoneScaleSize.Height * Zoom / 100 ) );

        
                    
                }

                //base.NoneScaleSize = new Size( base.NoneScaleSize.Width, slot.Top - this.NoneScaleLocation.Y + slot.Height + 5 );
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public override void ReLocate()
        {
            base.ReLocate();

            if ( base.Slots.Count > 0 )
            {
                int offset = 5 + ( int )( 5 * Zoom / 100 );
                int innerSpace = 2 + ( int )( 2 * Zoom / 100 );

                Slot slot = new Slot();

                for ( int i = 0; i < base.Slots.Count; i++ )
                {
                    slot = base.Slots[i];

                    base.Slots[i].Left = this.Location.X + this.Width - slot.Width;
                    //base.Slots[i].Left = this.Location.X + this.Width - slot.Width;
                    base.Slots[i].Top = this.Location.Y + offset;

                    offset += slot.Height + innerSpace;
                }

                //base.NoneScaleSize = new Size( base.NoneScaleSize.Width, slot.Top - this.NoneScaleLocation.Y + slot.Height + 5 );
            }

        }


    }
}
